package com.example.leetcode;

class Solution53 {
    public int maxSubArray(int[] nums) {
        int pre = 0;
        int maxAns = nums[0];
        for (int x : nums) {
            pre = Math.max(pre + x, x);
            System.out.print(pre);
            maxAns = Math.max(maxAns, pre);
            System.out.println(maxAns);
        }
        return maxAns;
    }


    public static void main(String[] args) {
        System.out.println(new Solution53().maxSubArray(new int[]{-2, 1, -3, 4, -1, 2, 1, -5, 4}));
    }
}